<template>
    <div class="com_box flexbox flexcolumn over_box height_100">
        <HeadStep :dataForm="dataForm"/>
        <div class="creat_task_name flexbox flexcenter">
            <el-form ref="createform" :model="createSubForm" size="small" :rules="createRules" :inline="true" class="create_form" :hide-required-asterisk='true'>
                <el-form-item label="" prop="title" style="margin-bottom:0">
                    <span>任务名称：</span>
                    <el-input v-model="createSubForm.queuename" placeholder="请输入内容" style="width:200px"></el-input>
                    <span>_{{getDateInfo()}}</span>
                </el-form-item>
                <el-form-item label="" prop="execution_time" style="margin-bottom:0">
                    <span>定时创建任务：</span>
                    <el-date-picker v-model="createSubForm.execution_time" :picker-options="pickerOptions" :clearable="false" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期"></el-date-picker>
                </el-form-item>
            </el-form>
        </div>
        <div class="adver_box over_box flex">
            <el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" class="com_table adver_table" height="100%">
                <el-table-column prop="plan_name" label="广告计划">
                    <template slot-scope="scope">
                        {{scope.row.plan_name}}
                    </template>
                </el-table-column>
                <el-table-column prop="ad_name" label="广告账户"></el-table-column>
                <el-table-column prop="bg_name" label="预算与出价"></el-table-column>
                <el-table-column prop="aud_name" label="定向人群"></el-table-column>
                <el-table-column prop="td_name" label="创意组">
                    <template slot-scope="scope">
                        {{(dataForm.market=='LIVE_PROM_GOODS'&&dataForm.createform.creative_way=="LIVE")?'直播间画面':scope.row.td_name}}
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="page_box flexbox flexcenter">
            <el-pagination background layout="total, prev, pager, next,sizes" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-size="pagesize" :page-sizes="[20, 50, 100, 200]" :total="tableData.length">
            </el-pagination>
        </div>
        <div class="create_footer">
            <el-button plain class="el-button-width plain_red" size="small" @click="cancelCreation">取消创建</el-button>
            <el-button plain class="el-button-width" size="small" @click="preStep">上一步</el-button>
            <el-button type="primary" class="el-button-width" size="small" :disabled="loading" :loading="loading" @click="submitForm('createform')">完成创建</el-button>
        </div>
    </div>
</template>

<script>
import HeadStep from './model/HeadStep';
export default {
    props: ["dataForm"],
    name: "",
    data() {
        return {
            pagesize: 20,
            currentPage: 1,
            tableData: [],
            loading: false,
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now() - 8.64e7;
                },
            },
            createSubForm: {
                queuename: "任务名称",
                execution_time: "",
                batch_create: {
                    name: "", //计划名称
                    marketing_goal: "", //营销目标
                    promotion_way: "", //推广方式
                    deep_external_action: "", //深度转化目标
                    accounts: [], //账户列表
                    external_action: "", //转化目标
                    creative_material_mode: "", //创意类型
                    creative_way: "", //创意形式
                    creative_auto_generate: "", //是否生成更多创意
                    is_homepage_hide: "", //抖音主页是否隐藏视频
                    delivery: [], //预算和出价
                    audience: [], //定向人群
                    creative: [], //创意列表
                    title: [
                        [
                            {
                                title: "",
                                dynamic_words: [],
                            },
                        ],
                    ], //标题列表
                    card: {},
                    creativity_class: [], //创意类型
                },
                type: "", //生成方式
                source: "", //数据缓存
            },
        };
    },
    created() {
        this.getTimeFn();
        let batch_create = this.createSubForm.batch_create;
        let createform = this.dataForm.createform;
        this.createSubForm.type = createform.type;
        batch_create.name = createform.name; //计划名称
        batch_create.marketing_goal = this.dataForm.market; //营销目标
        batch_create.promotion_way = this.dataForm.extension; //推广方式
        batch_create.external_action = createform.external_action; //转化目标
        batch_create.deep_external_action = createform.deep_external_action; //深度转化目标
        if (
            this.dataForm.market == "VIDEO_PROM_GOODS" &&
            this.dataForm.extension == "STANDARD"
        ) {
            batch_create.lab_ad_type = createform.lab_ad_type;
            if (createform.lab_ad_type == "LAB_AD") {
                batch_create.enable_auto_pause = createform.enable_auto_pause;
                batch_create.auto_manage_strategy_cmd =
                    createform.auto_manage_strategy_cmd;
                batch_create.enable_follow_material =
                    createform.enable_follow_material;
            }
        }
        if (
            this.dataForm.market == "LIVE_PROM_GOODS" &&
            this.dataForm.extension == "SIMPLE"
        ) {
            batch_create.lab_ad_type = createform.lab_ad_type;
        }
        if (createform.deep_external_action == "AD_CONVERT_TYPE_LIVE_PAY_ROI") {
            batch_create.roi_goal = createform.roi_goal;
            batch_create.deep_bid_type = createform.deep_bid_type;
        }
        batch_create.creative_material_mode = createform.creative_material_mode; //创意类型
        batch_create.creative_way =
            this.dataForm.market == "LIVE_PROM_GOODS"
                ? createform.creative_way
                : ""; //创意形式
        if (
            this.dataForm.market == "LIVE_PROM_GOODS" &&
            this.dataForm.extension == "SIMPLE"
        ) {
            if (createform.lab_ad_type == "LAB_AD") {
                if (createform.creative_way.length == 2) {
                    batch_create.creative_way = "LIVE";
                } else {
                    batch_create.creative_way = createform.creative_way[0];
                }
            }
        }
        if (
            this.dataForm.market == "LIVE_PROM_GOODS" ||
            this.dataForm.is_talent ||
            createform.external_action == "AD_CONVERT_TYPE_QC_FOLLOW_ACTION" ||
            createform.external_action == "AD_CONVERT_TYPE_QC_MUST_BUY"
        ) {
            batch_create.creative_auto_generate = "";
        } else if (
            this.dataForm.extension == "SIMPLE" &&
            !this.dataForm.is_talent
        ) {
            batch_create.creative_auto_generate = 1;
        } else {
            batch_create.creative_auto_generate =
                createform.external_action == "AD_CONVERT_TYPE_SHOPPING" ||
                this.dataForm.extension == "SIMPLE"
                    ? createform.creative_auto_generate
                    : 0; //是否生成更多创意
        }
        if (this.dataForm.is_talent) {
            batch_create.is_homepage_hide = 0;
        } else {
            batch_create.is_homepage_hide = createform.is_homepage_hide; //抖音主页是否隐藏视频
        }
        if (createform.lab_ad_type == "LAB_AD") {
            for (let i in this.dataForm.tableData) {
                //账户列表
                batch_create.accounts.push({
                    advertiser_id:
                        this.dataForm.tableData[i].hasAdver.advertiser_id,
                    advertiser_name: this.dataForm.tableData[i].hasAdver.name,
                    aweme_id: this.dataForm.tableData[i].hasAchor.aweme_id,
                    aweme_name: this.dataForm.tableData[i].hasAchor.aweme_name,
                    aweme_img: this.dataForm.tableData[i].hasAchor.aweme_avatar,
                    product_id: this.dataForm.tableData[i].hasShop.product_id,
                    product_name:
                        this.dataForm.tableData[i].hasShop.product_name,
                    product_img: this.dataForm.tableData[i].hasShop.img,
                });
            }
        } else {
            for (let i in this.dataForm.tableData) {
                //账户列表
                batch_create.accounts.push({
                    campaign_id: this.dataForm.tableData[i].hasGroup.id,
                    advertiser_id:
                        this.dataForm.tableData[i].hasAdver.advertiser_id,
                    advertiser_name: this.dataForm.tableData[i].hasAdver.name,
                    aweme_id: this.dataForm.tableData[i].hasAchor.aweme_id,
                    aweme_name: this.dataForm.tableData[i].hasAchor.aweme_name,
                    aweme_img: this.dataForm.tableData[i].hasAchor.aweme_avatar,
                    product_id: this.dataForm.tableData[i].hasShop.product_id,
                    product_name:
                        this.dataForm.tableData[i].hasShop.product_name,
                    product_img: this.dataForm.tableData[i].hasShop.img,
                });
            }
        }
        //预算出价
        if (
            this.dataForm.market == "LIVE_PROM_GOODS" &&
            this.dataForm.extension == "SIMPLE"
        ) {
            if (createform.lab_ad_type == "LAB_AD") {
                for (let i in createform.budget_list) {
                    batch_create.delivery.push({
                        delivery_name: createform.budget_list[i].model_name, //模板名称
                        smart_bid_type:
                            createform.budget_list[i].smart_bid_type, //投放方式
                        flow_control_mode: "FLOW_CONTROL_MODE_FAST", //投放速度
                        budget_mode: "BUDGET_MODE_DAY", //预算类型
                        budget: createform.budget_list[i].budget, //预算
                        cpa_bid:
                            createform.budget_list[i].smart_bid_type ==
                            "SMART_BID_CUSTOM"
                                ? createform.budget_list[i].cpa_bid
                                : "", //出价
                        live_schedule_type:
                            createform.budget_list[i].video_schedule_type, //投放日期-短视频
                        start_time:
                            createform.budget_list[i].video_schedule_type ==
                            "SCHEDULE_START_END"
                                ? createform.budget_list[i].start_time
                                : "", //开始日期
                        end_time:
                            createform.budget_list[i].video_schedule_type ==
                            "SCHEDULE_START_END"
                                ? createform.budget_list[i].end_time
                                : "", //结束日期
                    });
                }
            } else {
                for (let i in createform.budget_list) {
                    batch_create.delivery.push({
                        delivery_name: createform.budget_list[i].model_name, //模板名称
                        smart_bid_type:
                            createform.budget_list[i].smart_bid_type, //投放方式
                        flow_control_mode: "FLOW_CONTROL_MODE_FAST", //投放速度
                        budget_mode: "BUDGET_MODE_TOTAL", //预算类型
                        budget: createform.budget_list[i].budget, //预算
                        cpa_bid:
                            createform.budget_list[i].smart_bid_type ==
                            "SMART_BID_CUSTOM"
                                ? createform.budget_list[i].cpa_bid
                                : "", //出价
                        live_schedule_type: "SCHEDULE_TIME_FIXEDRANGE", //投放日期-直播带货-极速推广
                        schedule_fixed_range:
                            Number(
                                createform.budget_list[i].schedule_fixed_range
                            ) * 3600, //固定时长
                    });
                }
            }
        } else if (
            this.dataForm.market == "VIDEO_PROM_GOODS" &&
            this.dataForm.extension == "SIMPLE"
        ) {
            for (let i in createform.budget_list) {
                batch_create.delivery.push({
                    delivery_name: createform.budget_list[i].model_name, //模板名称
                    smart_bid_type: createform.budget_list[i].smart_bid_type, //投放方式
                    flow_control_mode: "FLOW_CONTROL_MODE_FAST", //投放速度
                    budget_mode: "BUDGET_MODE_DAY", //预算类型
                    budget: createform.budget_list[i].budget, //预算
                    cpa_bid:
                        createform.budget_list[i].smart_bid_type ==
                        "SMART_BID_CUSTOM"
                            ? createform.budget_list[i].cpa_bid
                            : "", //出价
                    video_schedule_type:
                        createform.budget_list[i].video_schedule_type, //投放日期-短视频
                    start_time:
                        createform.budget_list[i].video_schedule_type ==
                        "SCHEDULE_START_END"
                            ? createform.budget_list[i].start_time
                            : "", //开始日期
                    end_time:
                        createform.budget_list[i].video_schedule_type ==
                        "SCHEDULE_START_END"
                            ? createform.budget_list[i].end_time
                            : "", //结束日期
                    schedule_time:
                        createform.budget_list[i].launch_period == 2
                            ? createform.budget_list[i].schedule_time_value
                            : "", //投放时段
                });
            }
        } else {
            for (let i in createform.budget_list) {
                batch_create.delivery.push({
                    delivery_name: createform.budget_list[i].model_name, //模板名称
                    smart_bid_type: createform.budget_list[i].smart_bid_type, //投放方式
                    flow_control_mode: createform.budget_list[i].cost_control
                        ? "FLOW_CONTROL_MODE_SMOOTH"
                        : createform.budget_list[i].flow_control_mode, //投放速度
                    budget_mode:
                        createform.budget_list[i].video_schedule_type ==
                        "SCHEDULE_TIME_FIXEDRANGE"
                            ? "BUDGET_MODE_TOTAL"
                            : createform.budget_list[i].budget_mode, //预算类型
                    budget: createform.budget_list[i].budget, //预算
                    cpa_bid:
                        createform.budget_list[i].smart_bid_type ==
                        "SMART_BID_CUSTOM"
                            ? createform.budget_list[i].cpa_bid
                            : "", //出价
                    video_schedule_type:
                        this.dataForm.market == "VIDEO_PROM_GOODS"
                            ? createform.budget_list[i].video_schedule_type
                            : "", //投放日期-短视频
                    live_schedule_type:
                        this.dataForm.market == "LIVE_PROM_GOODS"
                            ? createform.budget_list[i].video_schedule_type
                            : "", //投放日期-直播带货
                    start_time:
                        createform.budget_list[i].video_schedule_type ==
                        "SCHEDULE_START_END"
                            ? createform.budget_list[i].start_time
                            : "", //开始日期
                    end_time:
                        createform.budget_list[i].video_schedule_type ==
                        "SCHEDULE_START_END"
                            ? createform.budget_list[i].end_time
                            : "", //结束日期
                    schedule_time:
                        createform.budget_list[i].launch_period == 2
                            ? createform.budget_list[i].schedule_time_value
                            : "", //投放时段
                    schedule_fixed_range:
                        createform.budget_list[i].video_schedule_type ==
                        "SCHEDULE_TIME_FIXEDRANGE"
                            ? Number(
                                  createform.budget_list[i].schedule_fixed_range
                              ) * 3600
                            : "", //固定时长
                });
            }
        }

        if (this.dataForm.extension == "SIMPLE") {
            // 人群定向
            if (createform.lab_ad_type == "LAB_AD") {
                for (let i in createform.audience_list) {
                    batch_create.audience.push({
                        audience_name: createform.audience_list[i].model_name, //模板名称
                        audience_mode:
                            createform.audience_list[i].audience_mode, //智能推荐
                        city: createform.audience_list[i].cityAllValue, //城市列表
                        district: createform.audience_list[i].district, //地域选项
                        location_type:
                            createform.audience_list[i].location_type, //地域定向的用户状态类型
                        gender: createform.audience_list[i].gender, //性别
                        age: createform.audience_list[i].age, //年龄
                        exclude_limited_region:
                            createform.audience_list[i].location_type ==
                            "CURRENT"
                                ? createform.audience_list[i]
                                      .exclude_limited_region
                                    ? createform.audience_list[i]
                                          .exclude_limited_region
                                    : 0
                                : "", //排除限定地区
                        aweme_fan_behaviors:
                            createform.audience_list[i].awemeRadio == 2
                                ? createform.audience_list[i]
                                      .aweme_fan_behaviors
                                : [], //抖音达人行为类型
                        aweme_fan_behaviors_days:
                            createform.audience_list[i].awemeRadio == 2
                                ? createform.audience_list[i]
                                      .aweme_fan_behaviors_days
                                : "", //抖音达人互动天数
                        aweme_fan_categories:
                            createform.audience_list[i].awemeRadio == 2
                                ? createform.audience_list[
                                      i
                                  ].tiktokTypeCheck.map((it) => {
                                      return it.id;
                                  })
                                : [], //抖音达人分类id
                        aweme_fan_accounts:
                            createform.audience_list[i].awemeRadio == 2
                                ? createform.audience_list[
                                      i
                                  ].titokTalentText.map((it) => {
                                      return it.id;
                                  })
                                : [], //抖音达人id
                        smart_interest_action:
                            createform.audience_list[i].smart_interest_action, //行为兴趣意向
                        action_scene:
                            createform.audience_list[i].smart_interest_action ==
                            "CUSTOM"
                                ? createform.audience_list[i].action_scene
                                : [], //行为场景
                        action_days:
                            createform.audience_list[i].smart_interest_action ==
                            "CUSTOM"
                                ? createform.audience_list[i].action_days
                                : "", //行为天数
                        action_categories:
                            createform.audience_list[i].smart_interest_action ==
                            "CUSTOM"
                                ? createform.audience_list[i].action_text.map(
                                      (it) => {
                                          return it.id;
                                      }
                                  )
                                : [], //行为类目词id
                        action_words:
                            createform.audience_list[i].smart_interest_action ==
                            "CUSTOM"
                                ? createform.audience_list[
                                      i
                                  ].action_key_text.map((it) => {
                                      return it.id;
                                  })
                                : [], //行为关键词id
                        interest_categories:
                            createform.audience_list[i].smart_interest_action ==
                            "CUSTOM"
                                ? createform.audience_list[i].interest_text.map(
                                      (it) => {
                                          return it.id;
                                      }
                                  )
                                : [], //兴趣类目词id
                        interest_words:
                            createform.audience_list[i].smart_interest_action ==
                            "CUSTOM"
                                ? createform.audience_list[
                                      i
                                  ].interest_key_text.map((it) => {
                                      return it.id;
                                  })
                                : [], //兴趣关键词id
                    });
                }
            } else {
                for (let i in createform.audience_list) {
                    batch_create.audience.push({
                        audience_name: createform.audience_list[i].model_name, //模板名称
                        audience_mode:
                            createform.audience_list[i].audience_mode, //智能推荐
                        city: createform.audience_list[i].cityAllValue, //城市列表
                        district: createform.audience_list[i].district, //地域选项
                        location_type:
                            createform.audience_list[i].location_type, //地域定向的用户状态类型
                        gender: createform.audience_list[i].gender, //性别
                        age: createform.audience_list[i].age, //年龄
                        exclude_limited_region:
                            createform.audience_list[i].location_type ==
                            "CURRENT"
                                ? createform.audience_list[i]
                                      .exclude_limited_region
                                    ? createform.audience_list[i]
                                          .exclude_limited_region
                                    : 0
                                : "", //排除限定地区
                        aweme_fan_behaviors:
                            createform.audience_list[i].awemeRadio == 2
                                ? createform.audience_list[i]
                                      .aweme_fan_behaviors
                                : [], //抖音达人行为类型
                        aweme_fan_behaviors_days:
                            createform.audience_list[i].awemeRadio == 2
                                ? createform.audience_list[i]
                                      .aweme_fan_behaviors_days
                                : "", //抖音达人互动天数
                        aweme_fan_categories:
                            createform.audience_list[i].awemeRadio == 2
                                ? createform.audience_list[
                                      i
                                  ].tiktokTypeCheck.map((it) => {
                                      return it.id;
                                  })
                                : [], //抖音达人分类id
                        aweme_fan_accounts:
                            createform.audience_list[i].awemeRadio == 2
                                ? createform.audience_list[
                                      i
                                  ].titokTalentText.map((it) => {
                                      return it.id;
                                  })
                                : [], //抖音达人id
                    });
                }
            }
        } else {
            // 人群定向
            for (let i in createform.audience_list) {
                batch_create.audience.push({
                    audience_name: createform.audience_list[i].model_name, //模板名称
                    city: createform.audience_list[i].cityAllValue, //城市列表
                    district: createform.audience_list[i].district, //地域选项
                    location_type: createform.audience_list[i].location_type, //地域定向的用户状态类型
                    gender: createform.audience_list[i].gender, //性别
                    age: createform.audience_list[i].age, //年龄
                    exclude_limited_region:
                        createform.audience_list[i].location_type == "CURRENT"
                            ? createform.audience_list[i].exclude_limited_region
                                ? createform.audience_list[i]
                                      .exclude_limited_region
                                : 0
                            : "", //排除限定地区
                    new_customer: createform.audience_list[i].new_customer
                        ? createform.audience_list[i].new_customer
                        : "NONE", //新客定向
                    aweme_fan_behaviors:
                        createform.audience_list[i].awemeRadio == 2
                            ? createform.audience_list[i].aweme_fan_behaviors
                            : [], //抖音达人行为类型
                    aweme_fan_behaviors_days:
                        createform.audience_list[i].awemeRadio == 2
                            ? createform.audience_list[i]
                                  .aweme_fan_behaviors_days
                            : "", //抖音达人互动天数
                    aweme_fan_categories:
                        createform.audience_list[i].awemeRadio == 2
                            ? createform.audience_list[i].tiktokTypeCheck.map(
                                  (it) => {
                                      return it.id;
                                  }
                              )
                            : [], //抖音达人分类id
                    aweme_fan_accounts:
                        createform.audience_list[i].awemeRadio == 2
                            ? createform.audience_list[i].titokTalentText.map(
                                  (it) => {
                                      return it.id;
                                  }
                              )
                            : [], //抖音达人id
                    retargeting_tags_exclude:
                        createform.audience_list[i].crowdRadio == 2
                            ? createform.audience_list[i].allCrowdCheck
                                  .map((it) => {
                                      if (it.retargeting_tags_op == "EXCLUDE") {
                                          return it.retargeting_tags_id;
                                      }
                                  })
                                  .filter(Boolean)
                            : [], //排除人群包id
                    retargeting_tags_include:
                        createform.audience_list[i].crowdRadio == 2
                            ? createform.audience_list[i].allCrowdCheck
                                  .map((it) => {
                                      if (it.retargeting_tags_op == "INCLUDE") {
                                          return it.retargeting_tags_id;
                                      }
                                  })
                                  .filter(Boolean)
                            : [], //定向人群包id
                    auto_extend_enabled:
                        createform.audience_list[i].auto_extend_enabled, //是否开启智能放量
                    auto_extend_targets:
                        createform.audience_list[i].auto_extend_enabled == 1
                            ? createform.audience_list[i].auto_extend_targets
                            : [], //开启智能放量参数
                    platform: createform.audience_list[i].platform
                        ? [createform.audience_list[i].platform]
                        : [], //平台
                    smart_interest_action:
                        createform.audience_list[i].smart_interest_action, //行为兴趣意向
                    action_scene:
                        createform.audience_list[i].smart_interest_action ==
                        "CUSTOM"
                            ? createform.audience_list[i].action_scene
                            : [], //行为场景
                    action_days:
                        createform.audience_list[i].smart_interest_action ==
                        "CUSTOM"
                            ? createform.audience_list[i].action_days
                            : "", //行为天数
                    action_categories:
                        createform.audience_list[i].smart_interest_action ==
                        "CUSTOM"
                            ? createform.audience_list[i].action_text.map(
                                  (it) => {
                                      return it.id;
                                  }
                              )
                            : [], //行为类目词id
                    action_words:
                        createform.audience_list[i].smart_interest_action ==
                        "CUSTOM"
                            ? createform.audience_list[i].action_key_text.map(
                                  (it) => {
                                      return it.id;
                                  }
                              )
                            : [], //行为关键词id
                    interest_categories:
                        createform.audience_list[i].smart_interest_action ==
                        "CUSTOM"
                            ? createform.audience_list[i].interest_text.map(
                                  (it) => {
                                      return it.id;
                                  }
                              )
                            : [], //兴趣类目词id
                    interest_words:
                        createform.audience_list[i].smart_interest_action ==
                        "CUSTOM"
                            ? createform.audience_list[i].interest_key_text.map(
                                  (it) => {
                                      return it.id;
                                  }
                              )
                            : [], //兴趣关键词id
                    ac: createform.audience_list[i].ac, //网络
                    live_platform_tags: [], //直播带货平台精选人群包-未知
                });
            }
        }

        // 创意列表
        let creative = [];
        for (let i in createform.creatinfo_list) {
            let children = [];
            for (let a in createform.creatinfo_list[i].creative) {
                children.push({
                    creative_name: createform.creatinfo_list[i].model_name, //模板名称
                    material_type:
                        createform.creatinfo_list[i].creative[a].material
                            .cate_type, //素材类型
                    material_source:
                        createform.creatinfo_list[i].creative[a].material
                            .material_source, //原数据类型
                    image_mode:
                        createform.creatinfo_list[i].creative[a].material
                            .cate_type == "video"
                            ? createform.creatinfo_list[i].creative[a].material
                                  .image_mode
                            : "LARGE_VERTICAL", //文件类型
                    aweme_item_id: createform.creatinfo_list[i].creative[a]
                        .material.aweme_item_id
                        ? createform.creatinfo_list[i].creative[a].material
                              .aweme_item_id
                        : "", //抖音视频ID
                    poster_url:
                        createform.creatinfo_list[i].creative[a].material
                            .img_url, //视频封面图地址
                    video_id:
                        createform.creatinfo_list[i].creative[a].material.id, //素材ID
                    design_id:
                        createform.creatinfo_list[i].creative[a].material.id, //素材库素材ID
                    image_url:
                        createform.creatinfo_list[i].creative[a].material
                            .cate_type == "video"
                            ? createform.creatinfo_list[i].creative[a].material
                                  .material
                            : createform.creatinfo_list[i].creative[a].material
                                  .material.url, //素材地址
                    image_name:
                        createform.creatinfo_list[i].creative[a].material
                            .material_name, //素材名称
                    poster_name:
                        createform.creatinfo_list[i].creative[a].material
                            .material_name, //素材名称
                    title: createform.creatinfo_list[i].creative[a].title, //标题
                    promotion_card_title:
                        createform.creatinfo_list[i].creative[a].card.car_name, //推广卡片标题
                    promotion_card_selling_points:
                        createform.creatinfo_list[i].creative[a].card.car_tag, //推广卡片卖点列表
                    promotion_card_image_name:
                        createform.creatinfo_list[i].creative[a].material
                            .material_name + "card", //推广卡片图片名称
                    promotion_card_image_url:
                        createform.creatinfo_list[i].creative[a].card.car_img, //推广卡片图片地址
                    promotion_card_button_smart_optimization:
                        createform.creatinfo_list[i].creative[a].card
                            .is_fisrtchoid, //启用智能优选
                    promotion_card_action_button:
                        createform.creatinfo_list[i].creative[a].card.car_link, //按钮文案
                    dynamic_words:
                        createform.creatinfo_list[i].creative[a].dynamic_words, //动态词包对象列表
                });
            }
            creative.push(children);
        }
        // console.log(createform.creative_way);
        // console.log(this.dataForm.market);
        // this.createSubForm.batch_create.creative = creative
        if (
            createform.creative_way == "LIVE" &&
            this.dataForm.market == "LIVE_PROM_GOODS"
        ) {
            this.createSubForm.batch_create.creative = [[]];
        } else {
            this.createSubForm.batch_create.creative = creative;
        }

        // 创意标题
        if (
            this.dataForm.createform.creative_material_mode ==
            "PROGRAMMATIC_CREATIVE"
        ) {
            let create_title = [];
            for (let i in createform.creattitle_list) {
                let children = [];
                for (let a in createform.creattitle_list[i].title) {
                    children.push({
                        title_name: createform.creattitle_list[i].model_name,
                        title: createform.creattitle_list[i].title[a].title, //创意标题
                        dynamic_words:
                            createform.creattitle_list[i].title[a]
                                .dynamic_words, //动态词包对象列表
                    });
                }
                create_title.push(children);
            }
            this.createSubForm.batch_create.title = create_title;
        }

        // 推广卡片
        this.createSubForm.batch_create.card.promotion_card_title =
            createform.card.car_name;
        this.createSubForm.batch_create.card.promotion_card_selling_points =
            createform.card.car_tag;
        this.createSubForm.batch_create.card.promotion_card_image_url =
            createform.card.car_img;
        this.createSubForm.batch_create.card.promotion_card_button_smart_optimization =
            createform.card.is_fisrtchoid;
        this.createSubForm.batch_create.card.promotion_card_action_button =
            createform.card.car_link;
        this.createSubForm.batch_create.card.promotion_card_image_name =
            createform.card.picture_name;

        let creativity_class = [];
        for (let i in createform.industry_list) {
            creativity_class.push({
                creativity_class_name: createform.industry_list[i].model_name,
                first_industry_id:
                    createform.industry_list[i].first_industry_id, //创意一级行业ID
                second_industry_id:
                    createform.industry_list[i].second_industry_id, //创意二级行业ID
                third_industry_id:
                    createform.industry_list[i].third_industry_id, //创意三级行业ID
                ad_keywords: createform.industry_list[i].ad_keywords, //创意标签
            });
        }
        this.createSubForm.batch_create.creativity_class = creativity_class;
        if (this.dataForm.createform.type == 1) {
            this.getDataList();
        } else if (this.dataForm.createform.type == 2) {
            let arr = [];
            let ad_user = this.dataForm.tableData; //抖音号
            let bg_list = this.dataForm.createform.budget_list; //预算
            let ad_list = this.dataForm.createform.audience_list; //定向
            let id_list = this.dataForm.createform.industry_list; //创意分类
            let td_list = this.dataForm.createform.creatinfo_list; //创意组
            let tt_list = this.dataForm.createform.creattitle_list; //标题组
            if (
                this.dataForm.market == "VIDEO_PROM_GOODS" ||
                this.dataForm.createform.creative_way == "VIDEO"
            ) {
                if (
                    this.dataForm.createform.creative_material_mode ==
                    "CUSTOM_CREATIVE"
                ) {
                    for (let a in ad_user) {
                        for (let b in bg_list) {
                            for (let c in ad_list) {
                                for (let d in id_list) {
                                    for (let e in td_list) {
                                        arr.push({
                                            plan_name:
                                                this.dataForm.createform
                                                    .exp_name,
                                            ad_name: ad_user[a].hasAdver.name,
                                            bg_name: bg_list[b].model_name,
                                            aud_name: ad_list[c].model_name,
                                            id_name: id_list[d].model_name,
                                            td_name: td_list[e].model_name,
                                        });
                                    }
                                }
                            }
                        }
                    }
                } else if (
                    this.dataForm.createform.creative_material_mode ==
                    "PROGRAMMATIC_CREATIVE"
                ) {
                    for (let a in ad_user) {
                        for (let b in bg_list) {
                            for (let c in ad_list) {
                                for (let d in id_list) {
                                    for (let e in td_list) {
                                        for (let f in tt_list) {
                                            arr.push({
                                                plan_name:
                                                    this.dataForm.createform
                                                        .exp_name,
                                                ad_name:
                                                    ad_user[a].hasAdver.name,
                                                bg_name: bg_list[b].model_name,
                                                aud_name: ad_list[c].model_name,
                                                id_name: id_list[d].model_name,
                                                td_name: td_list[e].model_name,
                                            });
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if (
                    this.dataForm.createform.creative_material_mode ==
                    "CUSTOM_CREATIVE"
                ) {
                    for (let a in ad_user) {
                        for (let b in bg_list) {
                            for (let c in ad_list) {
                                for (let d in id_list) {
                                    for (let e in td_list) {
                                        arr.push({
                                            plan_name:
                                                this.dataForm.createform
                                                    .exp_name,
                                            ad_name: ad_user[a].hasAdver.name,
                                            bg_name: bg_list[b].model_name,
                                            aud_name: ad_list[c].model_name,
                                            id_name: id_list[d].model_name,
                                            td_name: td_list[e].model_name,
                                        });
                                    }
                                }
                            }
                        }
                    }
                } else if (
                    this.dataForm.createform.creative_material_mode ==
                    "PROGRAMMATIC_CREATIVE"
                ) {
                    if(this.dataForm.createform.creative_way.includes('VIDEO')){
                        for (let a in ad_user) {
                            for (let b in bg_list) {
                                for (let c in ad_list) {
                                    for (let d in id_list) {
                                        for (let e in td_list) {
                                            for (let f in tt_list) {
                                                arr.push({
                                                    plan_name:
                                                        this.dataForm.createform
                                                            .exp_name,
                                                    ad_name:
                                                        ad_user[a].hasAdver.name,
                                                    bg_name: bg_list[b].model_name,
                                                    aud_name: ad_list[c].model_name,
                                                    id_name: id_list[d].model_name,
                                                    td_name: td_list[e].model_name,
                                                });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }else{
                        for (let a in ad_user) {
                            for (let b in bg_list) {
                                for (let c in ad_list) {
                                    for (let d in id_list) {
                                        for (let e in tt_list) {
                                            arr.push({
                                                plan_name:
                                                    this.dataForm.createform
                                                        .exp_name,
                                                ad_name:
                                                    ad_user[a].hasAdver.name,
                                                bg_name: bg_list[b].model_name,
                                                aud_name: ad_list[c].model_name,
                                                id_name: id_list[d].model_name,
                                                td_name: td_list[e].model_name,
                                            });
                                        }
                                    }
                                }
                            }
                        }
                    }
                    
                }
            }
            for (let i in arr) {
                arr[i].plan_name =
                    this.dataForm.createform.exp_name + (Number(i) + 1);
            }
            this.tableData = arr;
        }
        console.log(this.createSubForm);
    },
    computed: {},
    methods: {
        preStep() {
            this.dataForm.step = 3;
            window.sessionStorage.setItem(
                "dataForm",
                JSON.stringify(this.dataForm)
            );
        },

        //获取智能计划表格
        async getDataList() {
            const { data: res } = await this.$http.post(
                "launch/Getinfo/get_intellad",
                {
                    batch_create: this.createSubForm.batch_create,
                }
            );
            if (res.code !== 200) {
                this.loading = false;
                this.$message.error(res.msg);
                return;
            } else {
                for (let i in res.data) {
                    this.tableData.push({
                        plan_name: res.data[i].name,
                        ad_name: res.data[i].advertiser_name,
                        bg_name: res.data[i].delivery_name,
                        aud_name: res.data[i].audience_name,
                        td_name: res.data[i].creative_name,
                    });
                }
            }
        },

        getDateInfo() {
            let nowData = new Date();
            let year = nowData.getFullYear();
            let month =
                nowData.getMonth() + 1 < 10
                    ? "0" + (nowData.getMonth() + 1)
                    : nowData.getMonth() + 1;
            let date =
                nowData.getDate() < 10
                    ? "0" + nowData.getDate()
                    : nowData.getDate();
            let getData = year + "-" + month + "-" + date;
            return getData;
        },

        getTimeFn() {
            const date = new Date();
            this.createSubForm.execution_time = this.formatDate(date);
        },

        formatDate(date) {
            var myyear = date.getFullYear();
            var mymonth = date.getMonth() + 1;
            var myweekday = date.getDate();

            if (mymonth < 10) {
                mymonth = "0" + mymonth;
            }
            if (myweekday < 10) {
                myweekday = "0" + myweekday;
            }
            let hh =
                date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
            let mm =
                date.getMinutes() < 10
                    ? "0" + date.getMinutes()
                    : date.getMinutes();
            let ss =
                date.getSeconds() < 10
                    ? "0" + date.getSeconds()
                    : date.getSeconds();
            return (
                myyear +
                "-" +
                mymonth +
                "-" +
                myweekday +
                " " +
                hh +
                ":" +
                mm +
                ":" +
                ss
            );
        },

        // 每页显示多少条数据
        handleSizeChange(val) {
            this.pagesize = val;
        },
        // 当前页切换
        handleCurrentChange(val) {
            this.currentPage = val;
        },

        // 提交
        submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                if (valid) {
                    if (this.tableData.length > 300) {
                        this.$message.error("计划总数不能大于300条！");
                        return;
                    }
                    this.createSubForm.source = JSON.stringify(this.dataForm);
                    // console.log(this.createSubForm);
                    // return
                    this.loading = true;
                    const { data: res } = await this.$http.post(
                        "launch/Launch/plan_make",
                        this.createSubForm
                    );
                    if (res.code !== 200) {
                        this.$message.error(res.msg);
                        this.loading = false;
                        return;
                    } else {
                        this.$message({
                            message: "创建成功",
                            type: "success",
                        });
                        this.$router.push({
                            path: "/launch/Task/task_list",
                        });
                        sessionStorage.removeItem("dataForm");
                        this.loading = false;
                    }
                } else {
                    this.loading = false;
                    return false;
                }
            });
        },

        // 取消创建
        cancelCreation() {
            this.$confirm("是否取消？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    sessionStorage.removeItem("dataForm");
                    this.$parent.dataForm = JSON.parse(
                        JSON.stringify(this.$parent.resetForm)
                    );
                })
                .catch(() => {});
        },
    },
    components: {
        HeadStep
    },
};
</script>


<style scoped>
.creat_task_name {
    font-size: 14px;
    color: #616c85;
    padding: 0 20px;
}
.create_footer {
    padding: 20px;
    text-align: right;
    box-shadow: 0px -2px 11px rgba(213, 210, 210, 0.23);
}
.adver_box {
    padding: 20px;
}
</style>

